package basicservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type SupplierCertTypeAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSupplierCertTypeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplierCertTypeAddLogic {
	return &SupplierCertTypeAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// SupplierCertTypeAdd 创建厂商证件类型
func (l *SupplierCertTypeAddLogic) SupplierCertTypeAdd(in *property_service.SupplierCertType) (*property_service.Response, error) {
	// 获取厂商证件类型模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).SupplierCertType
	// 创建一个新的厂商证件类型模型对象，不包含ID、UpdatedAt、CreatedAt字段
	mod := &model.SupplierCertType{
		CertificateName: in.CertificateName, // 证件名称
		PinyinCode:      in.PinyinCode,      // 拼音简码
		Remark:          in.Remark,          // 备注
		TenantID:        in.TenantID,        // 租户ID
		CreatedAtuser:   in.CreatedAtuser,   // 创建用户
	}

	// 使用上下文执行创建操作
	if err := m.WithContext(l.ctx).Create(mod); err != nil {
		// 如果创建失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 创建成功，返回成功响应
	return result.Suc().AddEd()
}
